﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Model;
using University.Workshop.DataAccess;
using System.Windows.Forms;
using System.Collections.ObjectModel;
using System.Globalization;


namespace University.Workshop.Business
{
   public static class CheckInManager
    {
        public static String TokenRoomsForADay(DateTime date) {
            CheckInDataAccess checkInDal = new CheckInDataAccess();
            checkInDal.Dispose();
            return checkInDal.TokenRoomsForADay(date);
        }
        public static void CheckInClient(string roomName, string clientId, DateTime checkIn, DateTime checkout)
        {
            int iterator = 0;
            CheckInDataAccess checkInDal = new CheckInDataAccess();
            checkInDal.Dispose();
            RoomDataAccess roomDal = new RoomDataAccess();
            roomDal.Dispose();
            BookingDataAccess bookingDal = new BookingDataAccess();
            bookingDal.Dispose();

            if (roomName == "Seleccionar Un Cuarto") { throw new ArgumentException("Select A Room"); }
            if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(roomName)) { throw new ArgumentException("Invalid Inputs"); }
            if (clientId.Contains("label")) { throw new ArgumentException("Invalid Inputs"); }
            if (!BookingManager.ValidDateCheckInCheckout(checkIn, checkout)) { throw new ArgumentException("Invalid CheckOut Date"); }
            int roomId = roomDal.GetIdRoomByName(roomName);
            DateTime checkInConvert = Convert.ToDateTime(checkIn.ToShortDateString(), CultureInfo.CurrentCulture);
            DateTime checkOutConvert = Convert.ToDateTime(checkout.ToShortDateString(), CultureInfo.CurrentCulture);
            while (checkInConvert <= checkOutConvert)
            {
                checkInConvert = checkInConvert.AddDays(iterator);
                if (checkInDal.IsToken(roomId, checkInConvert)) { throw new ArgumentException("This Room Is All Ready Taken"); }
                if (bookingDal.IsBooked(roomId, checkInConvert)) { throw new ArgumentException("This Room Is All Ready Booked"); }
                iterator++;
            }

            checkInDal.CheckInAClient(roomId, clientId, checkIn, checkout);
        }
    }
}
